package kr.hyunist.androidcomplete01saeildamil.ch09;

import kr.hyunist.androidcomplete01saeildamil.*;
import android.app.*;
import android.graphics.*;
import android.os.*;
import android.view.*;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.*;

public class ContextMenuTest1 extends Activity {
	Button mBtn;
	EditText mEdit;
	MyImage mImage;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.contextmenu);

		mBtn = (Button) findViewById(R.id.contextmenubtn1);
		registerForContextMenu(mBtn);

		mEdit = (EditText) findViewById(R.id.contextmenuet1);
		registerForContextMenu(mEdit);

		mImage = (MyImage) findViewById(R.id.myImage1);
		registerForContextMenu(mImage);
	}

	@Override
	public void onCreateContextMenu(ContextMenu menu, View v,
			ContextMenuInfo menuInfo) {
		super.onCreateContextMenu(menu, v, menuInfo);

		if (v == mBtn) {
			menu.setHeaderTitle("Button Menu");
			menu.add(0, 1, 0, "RED");
			menu.add(0, 2, 0, "Green");
			menu.add(0, 3, 0, "Blue");
		}

		if (v == mEdit) {
			menu.add(0, 4, 0, "번역하기");
			menu.add(0, 5, 0, "필기인식");
		}
	}

	@Override
	public boolean onContextItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case 1:
			mBtn.setTextColor(Color.RED);
			return true;
			
		case 2:
			mBtn.setTextColor(Color.GREEN);
			return true;

		case 3:
			mBtn.setTextColor(Color.BLUE);
			return true;

		case 4:
			Toast.makeText(ContextMenuTest1.this, mEdit.getText(), Toast.LENGTH_SHORT).show();
			return true;

		case 5:
			Toast.makeText(ContextMenuTest1.this, "필기인식완료", Toast.LENGTH_SHORT).show();
			return true;

		case 100:
			Toast.makeText(ContextMenuTest1.this, "이미지 회전 완료", Toast.LENGTH_SHORT).show();
			return true;
			
		case 101:
			Toast.makeText(ContextMenuTest1.this, "크기 변경 완료", Toast.LENGTH_SHORT).show();
			return true;
		}

		return true;
	}
}
